{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# 软件调试\n",
    "软件调试是剔除软件中bug，加速软件开发的必经过程。\n",
    "\n",
    "我们调试方式有很多，我们当前我演示我们常用2种调试方式：通过prinf输出需要查看的信息，通过专用调试器(例如python中的pdb)进行调试。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 简单、粗暴的printf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用printf进行代码调试\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "\n",
    "if __name__ == \"__main__\":  \n",
    "    try:\n",
    "        \n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        for i in range(0,8):\n",
    "            #显示0~7数组\n",
    "            SAKS.digital_display.show((\"%4d\" % i).replace(' ','#'))\n",
    "            \n",
    "            print(\"当前显示的i值：\" + str(i))\n",
    "            \n",
    "            time.sleep(3)\n",
    "            \n",
    "        print(\"程序运行结束\")\n",
    "            \n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 更精准的调试器pdb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#python的pdb调试指令\n",
    "from IPython.display import Image\n",
    "Image(filename = \"./picture/python_pdb.jpg\", width=1024, height=768)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用printf进行代码调试\n",
    "import time\n",
    "from sakshat import SAKSHAT\n",
    "from sakspins import SAKSPins as PINS\n",
    "import pdb\n",
    "\n",
    "if __name__ == \"__main__\":  \n",
    "    try:\n",
    "        \n",
    "        #启动pdb服务\n",
    "        pdb.set_trace()\n",
    "\n",
    "        #Declare the SAKS Board\n",
    "        SAKS = SAKSHAT()\n",
    "        \n",
    "        for i in range(0,8):\n",
    "            #显示0~7数组\n",
    "            SAKS.digital_display.show((\"%4d\" % i).replace(' ','#'))\n",
    "            \n",
    "            print(\"当前显示的i值：\" + str(i))\n",
    "            \n",
    "            time.sleep(3)\n",
    "            \n",
    "        print(\"程序运行结束\")\n",
    "            \n",
    "        \n",
    "    except KeyboardInterrupt:\n",
    "        print(\"任务被终止了\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
